﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Xcj.Mes.WholeLine.DataBase.Entity;

namespace Xcj.Mes.WholeLine.Plc.Interface
{
    public interface IPlc : IDisposable
    {
        CancellationTokenSource cts { get; set; }

        string Name { get; set; }   // 名字，区分PLC

        string Brand { get; }       // 品牌

        string Model { get;  }      // 型号

        string Protocol { get;}     // 通信协议

        string IP { get;}           // IP地址

        int Port { get;}            // 通信端口

        bool IsConnected { get; }   // Plc是否已连接

        Dictionary<string, PlcAddressEntity> DictPlcAddress { get; }

        PlcConfigEntity PlcConfigEntity { get; set; }

        void Init();

        bool Connect();

        Task<bool> ConnectAsync();

        bool Connect(string ip, ushort port);

        Task<bool> ConnectAsync(string ip, ushort port);

        void Disconnect();

        Task DisconnectAsync();

        bool Read(string nStartAddr, ushort nCount, out bool[] values);

        bool Read(string nStartAddr, ushort nCount, out byte[] values);

        Task<T> ReadAsync<T>(string nStartAddr, ushort nCount);

        bool Read(string nStartAddr, ushort nCount, out Int16[] values);

        bool Read(string nStartAddr, ushort nCount, out UInt16[] values);

        bool Read(string nStartAddr, ushort nCount, out Int32[] values);

        bool Read(string nStartAddr, ushort nCount, out UInt32[] values);

        bool Read(string nStartAddr, ushort nCount, out Int64[] values);

        bool Read(string nStartAddr, ushort nCount, out UInt64[] values);

        bool Read(string nStartAddr, ushort nCount, out float[] values);

        bool Read(string nStartAddr, ushort nCount, out double[] values);

        bool Read(string nStartAddr, ushort length, out string values);

        Task<bool> WriteAsync<T>(string nStartAddr, ushort count, T datas);

        bool Write(string nStartAddr, ushort count, bool[] datas);

        bool Write(string nStartAddr, ushort count, byte[] datas);

        bool Write(string nStartAddr, ushort nCount, Int16[] values);

        bool Write(string nStartAddr, ushort nCount, UInt16[] values);

        bool Write(string nStartAddr, ushort nCount, Int32[] values);

        bool Write(string nStartAddr, ushort nCount, UInt32[] values);

        bool Write(string nStartAddr, ushort nCount, Int64[] values);

        bool Write(string nStartAddr, ushort nCount, UInt64[] values);

        bool Write(string nStartAddr, ushort nCount, float[] values);

        bool Write(string nStartAddr, ushort nCount, double[] values);

        bool Write(string nStartAddr, string value);
    }
}
